package com.glc.hms.core.compress.algorithm;

import lombok.extern.slf4j.Slf4j;
import net.jpountz.lz4.*;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * LZ4压缩算法
 *
 * @author Lin
 * @time 2019-12-04 22:16
 */
@Slf4j
public class LZ4CompressAlgorithm extends AbstractCompressAlgorithm {

    @Override
    protected OutputStream createOutputStream(OutputStream output) throws IOException {
        LZ4Compressor compressor = LZ4Factory.fastestInstance().fastCompressor();
        return new LZ4BlockOutputStream(output, BUFFER_SIZE, compressor);
    }

    @Override
    protected InputStream createInputStream(InputStream input) throws IOException {
        LZ4FastDecompressor decompressor = LZ4Factory.fastestInstance().fastDecompressor();
        return new LZ4BlockInputStream(input, decompressor);
    }
}
